package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

//Import all objectinfo components
import gui.components.objectinfo.*;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

public class ObjectInfo
{
	private static final String Arial = null;
	private JPanel pnl_ObjectInfo = new JPanel(new BorderLayout());
	
	//Default selected menu is objectinfo
	private static int selectedMenu = 2;
	
	//Create instances of objectinfo components
	public System_Exit se = new System_Exit();
	
	public void setSelectedMenu(int _selectedMenu) {
		selectedMenu = _selectedMenu;
	}

	public int getSelectedMenu() {
		return selectedMenu;
	}
	
	public JPanel getObjectInfo()
	{
		return pnl_ObjectInfo;
	}
	
	public ObjectInfo()
	{
		refreshObjectInfo();
	}
	
	public void refreshObjectInfo(){

		//Remove all elements from panel
		this.pnl_ObjectInfo.removeAll();
		
		//Add JtabbedPane to panel
		this.pnl_ObjectInfo.add(createJtabbedPane(getSelectedMenu()));
		
		//validate the new pane
		this.pnl_ObjectInfo.validate();
		
		//Repaint new elements
		this.pnl_ObjectInfo.repaint();
	}
	public JTabbedPane createJtabbedPane(int menuItem){
		/* MENU ITEMS
		 * 0 :: System	 * 1 :: Display	 * 2 :: Selection	 * 3 :: Sensors	 * 4 :: Tools	 * 5 :: Help
		 */
		// Define color for selected tab
		// Color rgbHighlight = new Color(162, 162, 162);
		// Create the JtabbedPane
		JTabbedPane pane = new JTabbedPane(JTabbedPane.LEFT);
		
		pane.setOpaque(false);
		
		pane.setUI(new BasicTabbedPaneUI() {
			@Override
			   protected void installDefaults() {
			       super.installDefaults();
			       shadow = Color.black;
			   }
			});
		// End color scheme
		
		// Based on menu selection create tabs
		switch(menuItem){
			case 0: 
				String[] system = {"general", "about", "exit"};
				createTabs(pane,system);
				break;
			case 1: 
				String[] view = {"toggles"};
				createTabs(pane,view);
				break;
			case 2: 
				String[] objectinfo = {"info"};
				createTabs(pane,objectinfo);
				break;
			default:
				break;
		}
		// Return pane
		return pane;
	}
	private void createTabs(JTabbedPane pane, String[] tabTitles){

		Font tabFont = new Font(Arial, Font.BOLD, 11);
		pane.setFont(tabFont);
		
		for(String title : tabTitles){
			JPanel panel = new JPanel();
			
			// Create vertical text of tab title (add spaces for aligning)
			vText tabTitle = new vText(panel, "   " + title.toUpperCase());
			
			// Add the tab info static based on selected menu item and tab name
			switch(getSelectedMenu()){
				case 0:
					if(title == "general"){
						panel.add(new System_General().createPanelElements());
					}
					else if(title == "about"){
						panel.add(new System_About().createPanelElements());
					}
					else if(title == "exit"){
						panel.add(new System_Exit().createPanelElements());
					}
					break;
				case 1:
					panel.add(new View_Toggles().createPanelElements());
					break;
				case 2:
					panel.add(new Objectinfo_Info().createPanelElements());
				default:
					break;
			}
			// Add tab to pane
			pane.addTab(null, tabTitle, panel);
		}
	}
}
